
// 形状类
abstract class Shape {
    abstract draw(): void;
}
class Circle extends Shape {
    draw() {
        console.log('绘制圆形');
    }
}
class Rectangle extends Shape {
    draw() {
        console.log('绘制矩形');
    }
}
class Star extends Shape {
    draw() {
        console.log('绘制五角星');
    }
}

/**
 * 
 * ColorfulShape extends Shape：ColorfulShape的实例就多了一个参数：Shape的实例，
   ColorfulShape原本只有颜色的功能，现在多了一个参数 Shape的实例，ColorfulShape就有了画形状的功能，这就是装饰器的意义，类似于原生实现
 * 
 */

// 在不改变 抽象颜色类 的基础上添加新的功能，就叫装饰器模式
abstract class ColorfulShape extends Shape {
    constructor(public shape: Shape) {
        super();
    }
    abstract draw(): void;
}
class RedColorfulShape extends ColorfulShape {
    draw() {
        this.shape.draw();
        console.log('把边框涂成红色');
    }
}
class GreenColorfulShape extends ColorfulShape {
    draw() {
        this.shape.draw();
        console.log('把边框涂成绿色');
    }
}
class YellowColorfulShape extends ColorfulShape {
    draw() {
        this.shape.draw();
        console.log('把边框涂成黄色');
    }
}
// 画一个红色的圆形
let redColorfulShape = new RedColorfulShape(new Circle());
redColorfulShape.draw();

let greenColorfulShape = new GreenColorfulShape(new Rectangle());
greenColorfulShape.draw();

let yellowColorfulShape = new YellowColorfulShape(new Star());
yellowColorfulShape.draw();
